Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add framework for rendering widgets #101

Merged
merged 3 commits into from
Mar 15, 2022
Merged

add framework for rendering widgets #101

merged 3 commits into from
Mar 15, 2022

Conversation

jwildfire
Copy link
Contributor

Overview

Inspired by a few requests for customizations to hepExplorer that aren't covered in safetyGraphics. This adds a render_widget() helper function for rendering widgets directly, which is basically just a reusable function created from safetyGraphics chart export code for widgets (generated from safetyGraphics::makeChartExport). hepExplorer is a wrapper that adds some basic defaults and the ability to pass custom settings via ...

@bzkrouse @xni7 Take a look and see what you think! Can discuss whether it's worth building this out further or leaving it as a simple behind-the-scenes utility next time we chat.

Test Code

hepExplorer() #render widget with defaults 
hepExplorer(group_cols=c("SEX","AGEGR1")) # Adding age group

library(yaml)
mapping_yaml<-"id_col: USUBJID
value_col: AVAL
measure_col: PARAM
measure_values:
  ALT: Alanine Aminotransferase (U/L)
  AST: Aspartate Aminotransferase (U/L)
  TB: Bilirubin (umol/L)
  ALP: Alkaline Phosphatase (U/L)
normal_col_low: A1LO
normal_col_high: A1HI
studyday_col: ADY
visit_col: VISIT
visitn_col: VISITNUM
unit_col: ''
baseline_flag_col: ''
baseline_flag_values: ''
analysis_flag_col: ''
analysis_flag_values: ''
"
mapping <- read_yaml(text=mapping_yaml)
render_widget(widgetName="safetyHistogram", data=safetyData::adam_adlbc, mapping=mapping) 
render_widget(widgetName="safetyResultsOverTime", data=safetyData::adam_adlbc, mapping=mapping) 

@jwildfire jwildfire requested review from bzkrouse and xni7 March 11, 2022 21:53
@jwildfire jwildfire self-assigned this Mar 11, 2022
Copy link
Contributor

@xni7 xni7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jwildfire , this is genius! Now are half way towards bringing {safetyexploreR} back! I like the yaml mapping from sg V2, which allows users to obtain from the UI. This saves tons of the R function parameter documentation that @bzkrouse did before! 😄 This solves the namespace issue and we don't have export a function for each widget.

Would it make sense to also add Shiny binding functions like in {safetyGraphics} prepareChart function? Something like below?

sgV2's chartsTab module is great, however, the following binding might add flexibility to drop a widget to a Shiny app without having to use tab UI.

#' @export
meta_widgetOutput <- function(outputId, widgetName, width = "100%", height = "400px") {
  
  htmlwidgets::shinyWidgetOutput(outputId, widgetName, width, height, package="safetyCharts")
  
}

#' @export
meta_renderWidget <- function(expr, widgetName, env = parent.frame(), quoted = FALSE) {
  
  widgetOutput <- function(outputId, width = "100%", height = "400px") {
    htmlwidgets::shinyWidgetOutput(outputId, widgetName, width, height, package="safetyCharts")
  }
  
  if (!quoted) { expr <- substitute(expr) } # force quoted
  
  params <- list(
    expr             = expr, 
    outputFunction   = widgetOutput, 
    env              = env, 
    quoted           = quoted,
    cacheHint        = "auto"
  )
  
  do.call( htmlwidgets::shinyRenderWidget, params)
}

@jwildfire
Copy link
Contributor Author

jwildfire commented Mar 12, 2022

Thanks for the review @xni7. I do like the idea of extending this a bit further, and maybe migrating/reusing a bit more of the chart rendering in safetyGraphics here in safetyCharts. Going to go ahead and release this first bit with v0.3 and then we can discuss extensions for future releases.

Filed #102 so we don't lose track of the shiny binding idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants